package jinyilw.swing.rlaf.utils;

import jinyilw.swing.ComponentTools;
import jinyilw.swing.FontTools;
import jinyilw.swing.ScreenTools;
import jinyilw.swing.SwingTools;
import jinyilw.swing.SystemTools;
import jinyilw.swing.i18n.ICSetting;
import jinyilw.swing.icon.LazyScaleIcon;
import jinyilw.swing.res.LoadClass;
import jinyilw.swing.rlaf.theme.DoubleColor;
import jinyilw.swing.visuals.Icomp.ILabel;
import jinyilw.swing.visuals.Icomp.IRichLabel;
import jinyilw.swing.visuals.Jcomp.JMouseActComp;
import jinyilw.swing.visuals.Jcomp.TransRichButton;
import jinyilw.swing.visuals.Rcomp.RDialog;
import jinyilw.swing.visuals.border.RTitledBorder;
import jinyilw.swing.visuals.label.LinkLabel;

import javax.swing.JPanel;
import java.awt.Color;
import java.awt.Container;
import java.awt.Window;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;

/**
 * @author Jinyi
 */
public class AboutLafDialog extends RDialog
{
	private static final long serialVersionUID = -927671352131814824L;

	JPanel themeFeature = new JPanel();
	ILabel[] iLabels = new ILabel[7];
	ILabel useLabel = new IRichLabel();
	ILabel codeLabel = new IRichLabel();
	JPanel myInfoLabel = new JPanel();

	JMouseActComp lxPanel = new JMouseActComp();
	ILabel qqLabel = new ILabel();
	LinkLabel label = new LinkLabel("http://user.qzone.qq.com/821073285/");
	String downloadAddr = "https://gitee.com/jinyilw/RLookAndFeel";
	TransRichButton downloadButton = new TransRichButton(
			new ICSetting("downloadAddr", "下载地址：" + downloadAddr,
					"Download：" + downloadAddr));

	public AboutLafDialog(Window owner)
	{
		super(owner);
		setSize(520, 420);
		setResizable(false);
		setLocationRelativeTo(null);
		initGUI();
	}

	private void initGUI()
	{
		// setOpacity(0.88f);
		setOptionStyle(80, 0.92f);
		Container contentPanel = getContentPane();
		contentPanel.setLayout(null);
		addMouseListener(new ThisContentPaneMouseListener());
		setTitle(new ICSetting("aboutString", "关于主题", "About Theme"));

		contentPanel.add(themeFeature);
		themeFeature.setLayout(null);
		themeFeature.setBorder(new RTitledBorder(
				new ICSetting("themeFeature", "主要特点", "Features")));
		themeFeature.setBounds(80, 10, 412, 230);

		for (int i = 0; i < iLabels.length; i++)
		{
			iLabels[i] = new IRichLabel();
			iLabels[i].setForeground(Color.yellow);
			iLabels[i].setBounds(10, 25 + i * 20, 398, 18);
			themeFeature.add(iLabels[i]);
		}
		iLabels[0].setText(new ICSetting("feature1", "1. 通用主题，易于使用；",
				"1. Universal theme, it is easy to use;"));
		iLabels[1].setText(new ICSetting("feature2", "2. 透明组件，多彩个性；",
				"2. Transparent components, colorful personality;"));
		iLabels[2].setText(new ICSetting("feature3", "3. 明暗切换，全局适配；",
				"3. Switch colors, it is global adaptation;"));
		iLabels[3].setText(new ICSetting("feature4", "4. 自定义背景透明度、模糊度及亮度；",
				"4. Customize background transparency, blur, and brightness;"), true);
		iLabels[4].setText(new ICSetting("feature5", "5. 自定义主题颜色、软件字体；",
				"5. Customize theme colors and global fonts;"));
		iLabels[5].setText(new ICSetting("feature6", "6. 自带文本组件复制、剪切、粘贴功能；",
				"6. Implement text component copy, cut, paste functions;"));
		iLabels[6].setText(new ICSetting("feature7", "7. 融入多语言设计，轻松实现软件国际化；",
				"7. Integrate multi-language design, easily realize "
						+ "internationalization;"), true);

		themeFeature.add(useLabel);
		useLabel.setBounds(10, iLabels[6].getY() + 30, 390, 18);
		useLabel.setForeground(Color.yellow);
		useLabel.setText(new ICSetting("useMethod", "使用方法:", "How to use:"));
		themeFeature.add(codeLabel);
		codeLabel.setBounds(10, useLabel.getY() + 20, 390, 18);
		codeLabel.setForeground(Color.yellow);
		codeLabel.setText(new ICSetting("addCode",
				"      仅需添加1行代码: UITools.initRLookAndFeel();",
				"        just add one line code: UITools.initRLookAndFeel();"));

		contentPanel.add(myInfoLabel);
		myInfoLabel.setLayout(null);
		myInfoLabel.setBorder(new RTitledBorder(
				new ICSetting("authorInformation", "作者信息", "Information"),
				FontTools.defaultFont, Color.CYAN));
		SwingTools.arrangeComponents(
				SwingTools.getIRichTextLabels("myInfo", new String[]{"姓  名：王进懿", "籍  "
								+ "贯：贵州剑河"},
						new String[]{"Name: Wang Jinyi", "Origin: Jianhe Guizhou"},
						Color.YELLOW),
				myInfoLabel,
				10, 28, 160, 18, 3);
		myInfoLabel.setBounds(80, 250, 185, 80);
		contentPanel.add(lxPanel);
		lxPanel.setBorder(
				new RTitledBorder(new ICSetting("Contact", "联系方式", "Contact"),
						FontTools.defaultFont, Color.CYAN));
		lxPanel.setLayout(null);
		lxPanel.setBounds(305, 250, 186, 80);
		lxPanel.add(qqLabel);
		lxPanel.setRolloverEnable(true);
		//		lxPanel.enableMouseAct();
		lxPanel.addClickOperator(o -> ScreenTools.showWeChat());
		lxPanel.setCursor(ComponentTools.handCursor);
		qqLabel.setText(new ICSetting("wechat", "微信：jinyilw", "WeChat: jinyilw"));
		qqLabel.setForeground(new DoubleColor(Color.BLUE, Color.GREEN));

		qqLabel.setBounds(10, 35, 185, 18);
		contentPanel.add(downloadButton);
		downloadButton.setForeground(Color.CYAN);
		downloadButton.setFont(FontTools.getSystemFont(11));
		downloadButton.setCursor(ComponentTools.handCursor);
		downloadButton.setBounds(95, 345, 380, 30);
		downloadButton.addClickOperator(o -> SystemTools.browseURI(downloadAddr));
		contentPanel.add(label);
		label.setBounds(15, 82, 50, 50);
		label.setIcon(LazyScaleIcon.getIcon(LoadClass.class, "appLogo.png"));
		label.setText("");
	}

	private class ThisContentPaneMouseListener extends MouseAdapter
	{
		@Override
		public void mouseClicked(MouseEvent e)
		{
			// WindowTools.hideWindowToBorder(AboutDialog.this, Direction.DOWN);
			dispose();
		}
	}
}
